import React, { useState } from 'react'
import {
    Form,
    Select,
    Slider,
    Button,
    Checkbox,
    Row,
    Col,
    Layout,
    Radio,
    message,
  } from 'antd';
  import request from '@/http';
import SecurityService from '@/pages/login/service';
import { EditObject, Login } from '../studentHome/login';
import { history } from '@/.umi/core/history';


export default function Xuanze() {
      
    const onFinish = async (values: any) => {
        if(SecurityService.getSecurity()){
            // console.log('Received values of form: ', values)
                await request.get('/api/Examination/Get1?sbjid='+values.checkboxgroup1+'&i='+values.checkboxgroup).then((response:any)=>{
                    if(response.code==200){
                        // history.push({
                            // pathname:'/student/sijuan',
                            // state:values
                            // })
                            history.push({
                                pathname:'/student/sijuan',
                                state:values
                                })
                        // console.log(response)
                    }else{
                      message.error(response.message)
                    }
                    })
        }else{
            setCurrentEditObject({isModalVisible:true})
        }  
    };
    const [currentEditObject, setCurrentEditObject] =
    React.useState<EditObject>({
      isModalVisible: false,
    });
    const [SubjectData, setSubjectData] = useState([
        {
          "subjectName": null,
          "id": null
        },]);
      const getSubject=async () => {
          await request.post('/api/Subject/subjectSearch').then((response:any)=>{
            if(response.code==200){
                setSubjectData(response.slists)
            }else{
              message.error(response.message)
            }
            })
      }
      React.useEffect(()=>{
        getSubject();
      },[])
    return (
        <>
            <Form
                    name="validate_other"
                    onFinish={onFinish}
                    initialValues={{'checkboxgroup':2,'checkboxgroup1':1}}
                >
                    <h1>科目选择</h1>
                <Form.Item name="checkboxgroup1"
                 rules={[
                    { required: true, message: '不能为空!' }
                    ]}
                >
                <Radio.Group>
                <div className="as1">
                {SubjectData
                    ? SubjectData.map((item: any, index: any) => {
                        return (
                            <div className='item'>
                                <Radio value={item.id}>{item.subjectName}</Radio>
                            </div>
                        );
                        })
                    : ''}
                    
                </div>
                </Radio.Group>
                </Form.Item>
                <h1>分类</h1>
                <div className='cl'>
                    <Form.Item name="checkboxgroup" label="题量"
                     rules={[
                        { required: true, message: '不能为空!' }
                        ]}
                    >
                        <Radio.Group>
                        <Row>
                            <Col span={8}>
                            <Radio value={1}>10</Radio>
                            </Col>
                            <Col span={8}>
                            <Radio value={2}>30</Radio>
                            </Col>
                            <Col span={8}>
                            <Radio value={3}>60</Radio>
                            </Col>
                            {/* <Col span={8}>
                            <Checkbox value="C" style={{ lineHeight: '32px' }}>
                                判断
                            </Checkbox>
                            </Col> */}
                        </Row>
                        </Radio.Group>
                    </Form.Item>

                    {/* <Form.Item name="slider" label="题数">
                        <Slider
                        marks={{
                            0: '0',
                            20: '20',
                            40: '40',
                            60: '60',
                            80: '80',
                            100: '100',
                        }}
                        />
                    </Form.Item> */}
                    <Form.Item>
                        <Button  type="primary"  htmlType="submit">
                        确定
                        </Button>
                    </Form.Item>
                </div>
                </Form>
                <Login editObject={currentEditObject}></Login>
        </>
    )
}
